package com.kujie.access.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kujie.access.domain.po.AccessEnterpriseRentalInformation;
import com.kujie.access.domain.po.AccessTenantManagement;
import com.kujie.access.domain.query.EnterpriseRentalInformationQuery;
import com.kujie.access.domain.vo.EnterpriseRentalInformationVO;
import com.kujie.access.enums.OverdueEnum;
import com.kujie.access.mapper.AccessEnterpriseRentalInformationMapper;
import com.kujie.access.mapper.AccessTenantManagementMapper;
import com.kujie.access.service.IEnterpriseRentalInformationService;
import com.kujie.common.core.domain.R;
import com.kujie.common.core.utils.DateUtil;
import com.kujie.common.core.utils.StringUtils;
import com.kujie.common.excel.utils.ExcelUtil;
import com.kujie.common.mybatis.core.page.PageQuery;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 企业租赁信息 impl
 *
 * @author check
 * @date 2025-07-03
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class EnterpriseRentalInformationServiceImpl implements IEnterpriseRentalInformationService {
    private final AccessEnterpriseRentalInformationMapper enterpriseLeaseInformationMapper;
    private final AccessTenantManagementMapper accessTenantManagementMapper;

    @Override
    public Page<EnterpriseRentalInformationVO> list(EnterpriseRentalInformationQuery enterpriseRentalInformationQuery, PageQuery pageQuery) {
        var result = pageQuery.build(new EnterpriseRentalInformationVO());

        // 根据企业法人、企业名称查询企业信息
        var accessTenantManagementLambdaQueryWrapper = new LambdaQueryWrapper<AccessTenantManagement>();
        accessTenantManagementLambdaQueryWrapper.like(StringUtils.isNotEmpty(enterpriseRentalInformationQuery.getCompanyName()), AccessTenantManagement::getCompanyName, enterpriseRentalInformationQuery.getCompanyName());
        accessTenantManagementLambdaQueryWrapper.like(StringUtils.isNotEmpty(enterpriseRentalInformationQuery.getCompanyLegelPerson()), AccessTenantManagement::getCompanyLegelPerson, enterpriseRentalInformationQuery.getCompanyLegelPerson());
        var accessTenantManagements = accessTenantManagementMapper.selectList(accessTenantManagementLambdaQueryWrapper);

        // companyUuid -> AccessTenantManagement
        var idToCompany = accessTenantManagements.stream().collect(Collectors.toMap(AccessTenantManagement::getCompanyUuid, Function.identity()));
        Set<String> companyUuids = idToCompany.keySet();

        // 构造企业租赁信息查询条件
        var accessEnterpriseRentalInformationLambdaQueryWrapper = new LambdaQueryWrapper<AccessEnterpriseRentalInformation>();
        accessEnterpriseRentalInformationLambdaQueryWrapper.in(CollectionUtil.isNotEmpty(companyUuids), AccessEnterpriseRentalInformation::getCompanyUuid, companyUuids);
        accessEnterpriseRentalInformationLambdaQueryWrapper.like(StringUtils.isNotEmpty(enterpriseRentalInformationQuery.getBuildingNo()), AccessEnterpriseRentalInformation::getBuildingNo, enterpriseRentalInformationQuery.getBuildingNo());
        accessEnterpriseRentalInformationLambdaQueryWrapper.like(StringUtils.isNotEmpty(enterpriseRentalInformationQuery.getRoomNumber()), AccessEnterpriseRentalInformation::getRoomNumber, enterpriseRentalInformationQuery.getRoomNumber());
        List<AccessEnterpriseRentalInformation> accessEnterpriseRentalInformations = enterpriseLeaseInformationMapper.selectList(accessEnterpriseRentalInformationLambdaQueryWrapper);

        // 构造返回参数
        var accessEnterpriseRentalInformationVOS = accessEnterpriseRentalInformations.stream()
            .map(accessEnterpriseRentalInformation -> {
                var accessTenantManagement = idToCompany.get(accessEnterpriseRentalInformation.getCompanyUuid());
                return new EnterpriseRentalInformationVO(accessEnterpriseRentalInformation, accessTenantManagement);
            }).toList();

        // 如果开启了逾期状态查询
        if (StringUtils.isNotEmpty(enterpriseRentalInformationQuery.getOverdueStatus())) {
            accessEnterpriseRentalInformationVOS = accessEnterpriseRentalInformationVOS.stream()
                .filter(e -> DateUtil.differentDaysByLocalDateOnDays(e.getRentExpirationDate(), LocalDate.now(), OverdueEnum.getByCode(enterpriseRentalInformationQuery.getOverdueStatus())))
                .toList();
        }

        List<EnterpriseRentalInformationVO> pagedList = accessEnterpriseRentalInformationVOS.stream()
            .skip((pageQuery.getPageNum() - 1) * pageQuery.getPageSize())
            .limit(pageQuery.getPageSize())
            .toList();

        result.setRecords(pagedList);
        result.setTotal(accessEnterpriseRentalInformationVOS.size());
        return result;
    }

    @Override
    public EnterpriseRentalInformationVO detail(String id) {
        // 查询申报信息
        var accessEnterpriseRentalInformationLambdaQueryWrapper = new LambdaQueryWrapper<AccessEnterpriseRentalInformation>();
        accessEnterpriseRentalInformationLambdaQueryWrapper.eq(AccessEnterpriseRentalInformation::getId, id);
        var accessEnterpriseRentalInformation = enterpriseLeaseInformationMapper.selectOne(accessEnterpriseRentalInformationLambdaQueryWrapper);

        // 查询企业信息
        var accessTenantManagementLambdaQueryWrapper = new LambdaQueryWrapper<AccessTenantManagement>();
        accessTenantManagementLambdaQueryWrapper.eq(AccessTenantManagement::getCompanyUuid, accessEnterpriseRentalInformation.getCompanyUuid());
        var accessTenantManagement = accessTenantManagementMapper.selectOne(accessTenantManagementLambdaQueryWrapper);

        // 构造响应参数
        return new EnterpriseRentalInformationVO(accessEnterpriseRentalInformation, accessTenantManagement);
    }

    @Override
    public int insertOrUpdate(EnterpriseRentalInformationVO enterpriseRentalInformationVO) {
        int i = 0;

        if (StringUtils.isEmpty(enterpriseRentalInformationVO.getCompanyUuid())) {
            String uuid = IdUtil.randomUUID();
            enterpriseRentalInformationVO.setCompanyUuid(uuid);
        }

        var accessTenantManagement = buildAccessTenantManagement(enterpriseRentalInformationVO);
        var accessEnterpriseRentalInformation = buildEnterpriseRentalInformation(enterpriseRentalInformationVO);

        // 查询是否已经存在相同的 company_uuid
        LambdaQueryWrapper<AccessTenantManagement> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AccessTenantManagement::getCompanyUuid, accessTenantManagement.getCompanyUuid()).or().eq(AccessTenantManagement::getCompanyName, accessTenantManagement.getCompanyName());

        AccessTenantManagement tenantExisting = accessTenantManagementMapper.selectOne(queryWrapper);
        if (tenantExisting != null) {
            i = i + accessTenantManagementMapper.update(accessTenantManagement, queryWrapper);
        } else {
            i = i + accessTenantManagementMapper.insert(accessTenantManagement);
        }

        // 查询是否已经存在相同的 company_uuid
        LambdaQueryWrapper<AccessEnterpriseRentalInformation> accessEnterpriseRentalInformationLambdaQueryWrapper = new LambdaQueryWrapper<>();
        accessEnterpriseRentalInformationLambdaQueryWrapper.eq(AccessEnterpriseRentalInformation::getCompanyUuid, accessEnterpriseRentalInformation.getCompanyUuid());
        AccessEnterpriseRentalInformation enterpriseExisting = enterpriseLeaseInformationMapper.selectOne(accessEnterpriseRentalInformationLambdaQueryWrapper);
        if (enterpriseExisting != null) {
            i = i + enterpriseLeaseInformationMapper.update(accessEnterpriseRentalInformation, accessEnterpriseRentalInformationLambdaQueryWrapper);
        } else {
            i = i + enterpriseLeaseInformationMapper.insert(accessEnterpriseRentalInformation);
        }

        return i;
    }

    @Override
    public int batchDelete(List<String> ids) {
        var accessEnterpriseRentalInformationLambdaQueryWrapper = new LambdaQueryWrapper<AccessEnterpriseRentalInformation>();
        accessEnterpriseRentalInformationLambdaQueryWrapper.in(CollectionUtil.isNotEmpty(ids), AccessEnterpriseRentalInformation::getCompanyUuid, ids);
        return enterpriseLeaseInformationMapper.delete(accessEnterpriseRentalInformationLambdaQueryWrapper);
    }

    @Override
    public List<EnterpriseRentalInformationVO> batchExport(EnterpriseRentalInformationQuery enterpriseRentalInformationQuery, HttpServletResponse response) {
        // 构建查询企业信息wrapper
        var accessTenantManagementLambdaQueryWrapper = new LambdaQueryWrapper<AccessTenantManagement>();
        List<AccessEnterpriseRentalInformation> accessEnterpriseRentalInformationList;

        // 判断是否是全量导出
        if (!enterpriseRentalInformationQuery.getIsAll()) {
            accessEnterpriseRentalInformationList = enterpriseLeaseInformationMapper.selectByIds(enterpriseRentalInformationQuery.getIds());
        } else {
            // 构建企业信息查询条件
            accessTenantManagementLambdaQueryWrapper.like(StringUtils.isNotEmpty(enterpriseRentalInformationQuery.getCompanyName()), AccessTenantManagement::getCompanyName, enterpriseRentalInformationQuery.getCompanyName());
            accessTenantManagementLambdaQueryWrapper.like(StringUtils.isNotEmpty(enterpriseRentalInformationQuery.getCompanyLegelPerson()), AccessTenantManagement::getCompanyLegelPerson, enterpriseRentalInformationQuery.getCompanyLegelPerson());

            // 政策申报查询
            var accessEnterpriseRentalInformationLambdaQueryWrapper = new LambdaQueryWrapper<AccessEnterpriseRentalInformation>();
            accessEnterpriseRentalInformationLambdaQueryWrapper.like(StringUtils.isNotEmpty(enterpriseRentalInformationQuery.getBuildingNo()), AccessEnterpriseRentalInformation::getBuildingNo, enterpriseRentalInformationQuery.getBuildingNo());
            accessEnterpriseRentalInformationLambdaQueryWrapper.like(StringUtils.isNotEmpty(enterpriseRentalInformationQuery.getRoomNumber()), AccessEnterpriseRentalInformation::getRoomNumber, enterpriseRentalInformationQuery.getRoomNumber());
            accessEnterpriseRentalInformationList = enterpriseLeaseInformationMapper.selectList(accessEnterpriseRentalInformationLambdaQueryWrapper);
        }

        var companyUUIDs = accessEnterpriseRentalInformationList.stream().map(AccessEnterpriseRentalInformation::getCompanyUuid).toList();

        // 补全企业信息wrapper条件
        accessTenantManagementLambdaQueryWrapper.in(CollectionUtil.isNotEmpty(companyUUIDs), AccessTenantManagement::getCompanyUuid, companyUUIDs);
        var companyUuidToInformation = accessTenantManagementMapper.selectList(accessTenantManagementLambdaQueryWrapper).stream().collect(Collectors.toMap(AccessTenantManagement::getCompanyUuid, Function.identity()));
        return accessEnterpriseRentalInformationList.stream().map(e -> new EnterpriseRentalInformationVO(e, companyUuidToInformation.get(e.getCompanyUuid()))).toList();
    }

    @Override
    public int batchImport(MultipartFile file) throws IOException {
        var accessEnterpriseRentalInformations = new ArrayList<AccessEnterpriseRentalInformation>();
        var accessTenantManagements = new ArrayList<AccessTenantManagement>();

        // 提取EXCEL的数据
        var enterpriseRentalInformationVOS = ExcelUtil.importExcel(file.getInputStream(), EnterpriseRentalInformationVO.class);
        if (CollectionUtils.isEmpty(enterpriseRentalInformationVOS)) {
            log.info("数据为空");
            return 0;
        }

        // 获取企业信息
        List<String> companyNames = enterpriseRentalInformationVOS.stream().map(EnterpriseRentalInformationVO::getCompanyName).toList();
        var accessTenantManagementLambdaQueryWrapper = new LambdaQueryWrapper<AccessTenantManagement>();
        accessTenantManagementLambdaQueryWrapper.in(CollectionUtil.isNotEmpty(companyNames), AccessTenantManagement::getCompanyName, companyNames);

        List<AccessTenantManagement> accessTenantManagementList = accessTenantManagementMapper.selectList(accessTenantManagementLambdaQueryWrapper);
        var nameToAccessTenant = accessTenantManagementList.stream().collect(Collectors.toMap(AccessTenantManagement::getCompanyName, Function.identity()));

        // 本地缓存以防企业信息与租赁信息一对多的uuid情况
        Map<String, String> companyNameToCompanyUuid = new HashMap<>();

        // 已经添加过的公司名称
        Set<String> companyNameSet = new HashSet<>();

        // 企业uuid是否已经存在在表中
        List<String> companyList = accessTenantManagementList.stream().map(AccessTenantManagement::getCompanyUuid).toList();
        Map<String, AccessEnterpriseRentalInformation> companyUuidToPolicy = enterpriseLeaseInformationMapper.selectList(new LambdaQueryWrapper<AccessEnterpriseRentalInformation>()
            .in(CollectionUtil.isNotEmpty(companyList), AccessEnterpriseRentalInformation::getCompanyUuid, companyList)).stream().collect(Collectors.toMap(AccessEnterpriseRentalInformation::getCompanyUuid, Function.identity()));

        // 获取更新、新增数据
        for (EnterpriseRentalInformationVO enterpriseRentalInformationVO : enterpriseRentalInformationVOS) {
            // 构造对象
            AccessTenantManagement accessTenantManagement = new AccessTenantManagement();
            AccessEnterpriseRentalInformation accessEnterpriseRentalInformation = new AccessEnterpriseRentalInformation();

            // 设置UUID
            setUUID(enterpriseRentalInformationVO, nameToAccessTenant, accessTenantManagement, accessEnterpriseRentalInformation, companyNameToCompanyUuid);

            // 设置企业信息参数
            setAccessTenantManagement(enterpriseRentalInformationVO, accessTenantManagement, nameToAccessTenant);

            // 政策申报参数
            setEnterpriseRentalInformation(enterpriseRentalInformationVO, accessEnterpriseRentalInformation, companyUuidToPolicy);

            // 添加企业租赁信息
            accessEnterpriseRentalInformations.add(accessEnterpriseRentalInformation);

            // 添加企业信息，企业信息中企业只能唯一
            if (!companyNameSet.contains(enterpriseRentalInformationVO.getCompanyName())) {
                accessTenantManagements.add(accessTenantManagement);
                companyNameSet.add(enterpriseRentalInformationVO.getCompanyName());
            }
        }

        List<BatchResult> tenantResults = accessTenantManagementMapper.insertOrUpdate(accessTenantManagements);
        List<BatchResult> submitResults = enterpriseLeaseInformationMapper.insertOrUpdate(accessEnterpriseRentalInformations);
        return tenantResults.size() + submitResults.size();
    }

    @Override
    public List<EnterpriseRentalInformationVO> detailList(String companyUuid) {
        List<EnterpriseRentalInformationVO> enterpriseRentalInformationVOS = new ArrayList<>();
        // 查询申报信息
        var accessEnterpriseRentalInformationLambdaQueryWrapper = new LambdaQueryWrapper<AccessEnterpriseRentalInformation>();
        accessEnterpriseRentalInformationLambdaQueryWrapper.eq(AccessEnterpriseRentalInformation::getCompanyUuid, companyUuid);
        var accessEnterpriseRentalInformations = enterpriseLeaseInformationMapper.selectList(accessEnterpriseRentalInformationLambdaQueryWrapper);

        // 查询企业信息
        var accessTenantManagementLambdaQueryWrapper = new LambdaQueryWrapper<AccessTenantManagement>();
        accessTenantManagementLambdaQueryWrapper.eq(AccessTenantManagement::getCompanyUuid, companyUuid);
        var accessTenantManagement = accessTenantManagementMapper.selectOne(accessTenantManagementLambdaQueryWrapper);

        // 构建响应
        for (AccessEnterpriseRentalInformation accessEnterpriseRentalInformation : accessEnterpriseRentalInformations) {
            enterpriseRentalInformationVOS.add(new EnterpriseRentalInformationVO(accessEnterpriseRentalInformation, accessTenantManagement));
        }

        // 构造响应参数
        return enterpriseRentalInformationVOS;
    }

    private void setEnterpriseRentalInformation(EnterpriseRentalInformationVO enterpriseRentalInformationVO, AccessEnterpriseRentalInformation accessEnterpriseRentalInformation, Map<String, AccessEnterpriseRentalInformation> companyUuidToPolicy) {
        if (companyUuidToPolicy.containsKey(accessEnterpriseRentalInformation.getCompanyUuid())) {
            accessEnterpriseRentalInformation.setId(companyUuidToPolicy.get(accessEnterpriseRentalInformation.getCompanyUuid()).getId());
        }
        accessEnterpriseRentalInformation.setBuildingNo(enterpriseRentalInformationVO.getBuildingNo());
        accessEnterpriseRentalInformation.setRoomNumber(enterpriseRentalInformationVO.getRoomNumber());
        accessEnterpriseRentalInformation.setArea(enterpriseRentalInformationVO.getArea());
        accessEnterpriseRentalInformation.setSignDate(enterpriseRentalInformationVO.getSignDate());
        accessEnterpriseRentalInformation.setTermOfLease(enterpriseRentalInformationVO.getTermOfLease());
        accessEnterpriseRentalInformation.setLeaseDate(enterpriseRentalInformationVO.getLeaseDate());
        accessEnterpriseRentalInformation.setExpireDate(enterpriseRentalInformationVO.getExpireDate());
        accessEnterpriseRentalInformation.setRentFreePeriod(enterpriseRentalInformationVO.getRentFreePeriod());
        accessEnterpriseRentalInformation.setRentFreePeriodDate(enterpriseRentalInformationVO.getRentFreePeriodDate());
        accessEnterpriseRentalInformation.setGeneralOrder(enterpriseRentalInformationVO.getGeneralOrder());
        accessEnterpriseRentalInformation.setRentPerUnit(enterpriseRentalInformationVO.getRentPerUnit());
        accessEnterpriseRentalInformation.setMonthlyRent(enterpriseRentalInformationVO.getMonthlyRent());
        accessEnterpriseRentalInformation.setEarnestMoney(enterpriseRentalInformationVO.getEarnestMoney());
        accessEnterpriseRentalInformation.setQuarterlyRent(enterpriseRentalInformationVO.getQuarterlyRent());
        accessEnterpriseRentalInformation.setRentExpirationDate(enterpriseRentalInformationVO.getRentExpirationDate());
        accessEnterpriseRentalInformation.setCompletionDate(enterpriseRentalInformationVO.getCompletionDate());
        accessEnterpriseRentalInformation.setLeaseTerminationDate(enterpriseRentalInformationVO.getLeaseTerminationDate());
        accessEnterpriseRentalInformation.setIsHardcover(enterpriseRentalInformationVO.getIsHardcover());
        accessEnterpriseRentalInformation.setReferralSituation(enterpriseRentalInformationVO.getReferralSituation());
        accessEnterpriseRentalInformation.setSpecialApprovalMatters(enterpriseRentalInformationVO.getSpecialApprovalMatters());
        accessEnterpriseRentalInformation.setPropertyConsultant(enterpriseRentalInformationVO.getPropertyConsultant());
        accessEnterpriseRentalInformation.setRemark(enterpriseRentalInformationVO.getRemark());
    }

    private void setAccessTenantManagement(EnterpriseRentalInformationVO enterpriseRentalInformationVO, AccessTenantManagement accessTenantManagement, Map<String, AccessTenantManagement> nameToAccessTenant) {
        if (nameToAccessTenant.containsKey(enterpriseRentalInformationVO.getCompanyName())) {
            accessTenantManagement.setId(nameToAccessTenant.get(enterpriseRentalInformationVO.getCompanyName()).getId());
        }
        accessTenantManagement.setCompanyName(enterpriseRentalInformationVO.getCompanyName());
        accessTenantManagement.setAdministrativeContactPerson(enterpriseRentalInformationVO.getContact());
        accessTenantManagement.setAdministrativeContactPersonPhone(enterpriseRentalInformationVO.getContactPhone());
        accessTenantManagement.setCompanyLegelPerson(enterpriseRentalInformationVO.getCompanyLegelPerson());
        accessTenantManagement.setLegelIdCard(enterpriseRentalInformationVO.getCompanyLegelIdCard());
    }

    private void setUUID(EnterpriseRentalInformationVO enterpriseRentalInformationVO, Map<String, AccessTenantManagement> nameToAccessTenant, AccessTenantManagement accessTenantManagement,
                         AccessEnterpriseRentalInformation accessEnterpriseRentalInformation, Map<String, String> companyNameToCompanyUuid) {
        if (nameToAccessTenant.containsKey(enterpriseRentalInformationVO.getCompanyName())) {
            accessTenantManagement.setId(nameToAccessTenant.get(enterpriseRentalInformationVO.getCompanyName()).getId());
            accessTenantManagement.setCompanyUuid(nameToAccessTenant.get(enterpriseRentalInformationVO.getCompanyName()).getCompanyUuid());
            accessEnterpriseRentalInformation.setCompanyUuid(nameToAccessTenant.get(enterpriseRentalInformationVO.getCompanyName()).getCompanyUuid());
        } else {
            String uuid = "";
            if (companyNameToCompanyUuid.containsKey(enterpriseRentalInformationVO.getCompanyName())) {
                uuid = companyNameToCompanyUuid.get(enterpriseRentalInformationVO.getCompanyName());
            } else {
                uuid = IdUtil.randomUUID();
                companyNameToCompanyUuid.put(enterpriseRentalInformationVO.getCompanyName(), uuid);
            }
            accessTenantManagement.setCompanyUuid(uuid);
            accessEnterpriseRentalInformation.setCompanyUuid(uuid);
        }
    }

    private AccessEnterpriseRentalInformation buildEnterpriseRentalInformation(EnterpriseRentalInformationVO enterpriseRentalInformationVO) {
        AccessEnterpriseRentalInformation accessEnterpriseRentalInformation = new AccessEnterpriseRentalInformation();
        accessEnterpriseRentalInformation.setCompanyUuid(enterpriseRentalInformationVO.getCompanyUuid());
        accessEnterpriseRentalInformation.setBuildingNo(enterpriseRentalInformationVO.getBuildingNo());
        accessEnterpriseRentalInformation.setRoomNumber(enterpriseRentalInformationVO.getRoomNumber());
        accessEnterpriseRentalInformation.setArea(enterpriseRentalInformationVO.getArea());
        accessEnterpriseRentalInformation.setSignDate(enterpriseRentalInformationVO.getSignDate());
        accessEnterpriseRentalInformation.setTermOfLease(enterpriseRentalInformationVO.getTermOfLease());
        accessEnterpriseRentalInformation.setLeaseDate(enterpriseRentalInformationVO.getLeaseDate());
        accessEnterpriseRentalInformation.setExpireDate(enterpriseRentalInformationVO.getExpireDate());
        accessEnterpriseRentalInformation.setRentFreePeriod(enterpriseRentalInformationVO.getRentFreePeriod());
        accessEnterpriseRentalInformation.setRentFreePeriodDate(enterpriseRentalInformationVO.getRentFreePeriodDate());
        accessEnterpriseRentalInformation.setGeneralOrder(enterpriseRentalInformationVO.getGeneralOrder());
        accessEnterpriseRentalInformation.setRentPerUnit(enterpriseRentalInformationVO.getRentPerUnit());
        accessEnterpriseRentalInformation.setMonthlyRent(enterpriseRentalInformationVO.getMonthlyRent());
        accessEnterpriseRentalInformation.setEarnestMoney(enterpriseRentalInformationVO.getEarnestMoney());
        accessEnterpriseRentalInformation.setQuarterlyRent(enterpriseRentalInformationVO.getQuarterlyRent());
        accessEnterpriseRentalInformation.setRentExpirationDate(enterpriseRentalInformationVO.getRentExpirationDate());
        accessEnterpriseRentalInformation.setCompletionDate(enterpriseRentalInformationVO.getCompletionDate());
        accessEnterpriseRentalInformation.setLeaseTerminationDate(enterpriseRentalInformationVO.getLeaseTerminationDate());
        accessEnterpriseRentalInformation.setIsHardcover(enterpriseRentalInformationVO.getIsHardcover());
        accessEnterpriseRentalInformation.setReferralSituation(enterpriseRentalInformationVO.getReferralSituation());
        accessEnterpriseRentalInformation.setSpecialApprovalMatters(enterpriseRentalInformationVO.getSpecialApprovalMatters());
        accessEnterpriseRentalInformation.setPropertyConsultant(enterpriseRentalInformationVO.getPropertyConsultant());
        accessEnterpriseRentalInformation.setRemark(enterpriseRentalInformationVO.getRemark());
        return accessEnterpriseRentalInformation;
    }

    private AccessTenantManagement buildAccessTenantManagement(EnterpriseRentalInformationVO enterpriseRentalInformationVO) {
        AccessTenantManagement accessTenantManagement = new AccessTenantManagement();
        accessTenantManagement.setCompanyUuid(enterpriseRentalInformationVO.getCompanyUuid());
        accessTenantManagement.setCompanyName(enterpriseRentalInformationVO.getCompanyName());
        accessTenantManagement.setAdministrativeContactPerson(enterpriseRentalInformationVO.getContact());
        accessTenantManagement.setAdministrativeContactPersonPhone(enterpriseRentalInformationVO.getContactPhone());
        accessTenantManagement.setCompanyLegelPerson(enterpriseRentalInformationVO.getCompanyLegelPerson());
        accessTenantManagement.setLegelIdCard(enterpriseRentalInformationVO.getCompanyLegelIdCard());
        return accessTenantManagement;
    }
}
